<template>
    <div class="container">
      <!-- <svg id="barcode" /> -->
        <div class="opt-area-02">
            <div class="right-con">
<!--              <div class="input-frame" style="width: 164px">-->
<!--                  <Input type="text" @on-click="selectlist(1)" placeholder="预约编号" style="width: 164px" v-model="params.appoint_code"-->
<!--                          icon="ios-search"/>-->
<!--              </div>-->
<!--              <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px">搜索</Button>-->
              <Button type="info" size="small" @click="setAppoint('add')" style="margin-top: 5px;margin-left:5px">添加机构</Button>
            </div>
        </div>
        <Table :loading="countData.loading" border :columns="columns1" :data="fcDataList" size="small" ref="table">
            <template slot="action" slot-scope="{ row }">
                <Row style="margin-bottom: 5px; margin-top: 2px">
                    <Button class="table-action-btn" type="info" size="small"  @click="deleteAppoint(row)">删除</Button>
                    <Button class="table-action-btn" type="success" size="small" @click="showdetail(row, 'edit')">编辑</Button>
                </Row>
            </template>
        </Table>
        <!-- <Row v-if="loadData == true">
          <Col class="demo-spin-col" span="8" offset="8">
            <Spin fix>
              <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
              <div>Loading</div>
            </Spin>
          </Col>
        </Row> -->
        <Row type="flex" justify="end" class="page_style">
          <Page :current="currentPageNo" :total="totalnum" show-sizer :page-size="currentPageSize"
                show-total @on-change="changePageNo" @on-page-size-change="pageSizeChange"/>
        </Row>
        <Modal v-model="personShow" title="预约人员明细" width="1000" :closable="false">
          <Table border :columns="columns2" :data="data2">
            <template slot-scope="{ row }" slot="state">
              <span v-if="row.state == '0'">未取消</span>
              <span v-if="row.state == '1'">已取消</span>
            </template>
          </Table>
          <Row type="flex" justify="end" class="page_style">
            <Page :current="currentPageNo1" :total="totalnum1" :page-size="currentPageSize1"
                  show-total @on-change="changePageNo1"/>
          </Row>
        </Modal>
        <Modal v-model="appointObj.modal" :title="appointObj.title" @on-ok="okAppoint" @on-cancel="cancelAppoint">
          <Form label-position="right" :label-width="100">
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">检测机构名称：</Col>
              <Col span="14" class="ivu-form-item-content">
                <Input type="text" v-model="formItem.jc_name"></Input>
              </Col>
            </Row>
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">检测机构类型：</Col>
              <Col span="14" class="ivu-form-item-content">
                <Select v-model="formItem.jc_type" placeholder="请选择检测机构类型">
                  <Option value="0">区属</Option>
                  <Option value="1">市属</Option>
                </Select>
              </Col>
            </Row>
            <Row class="mb20" v-show="formItem.jc_type === '0'">
              <Col span="7" class="ivu-form-item-label">区属编码：</Col>
              <Col span="14" class="ivu-form-item-content">
                <Select v-model="formItem.jc_type_code">
                  <Option :value="obj.code" v-for="obj in inspectionArr" v-bind:key="obj.code">{{obj.name}}</Option>
                </Select>
              </Col>
            </Row>
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">日检测能力：</Col>
              <Col span="14" class="ivu-form-item-content">
                <Input type="number" v-model="formItem.jc_max_num"></Input>
              </Col>
            </Row>
          </Form>
        </Modal>
        <!-- <barcode :value="barcodes" id="aaa" :options="barcode_option" tag="svg" ></barcode> -->
    </div>
</template>

<script>
import { getQuList, getCompanyJCList, createCompanyJC, updateCompanyJCByCode, getAppointPersonList, deleteCompanyJCByCode } from '@/api/nucleic-acid-detection'
// import JsBarcode from 'jsbarcode'
// import VueBarcode from '@xkeshi/vue-barcode'
// import { date0str } from '@/api/eventlist'
// import { config } from 'vue/types/umd'
// import { getCityList } from '@/api/common'
// import { forEach } from '@/libs/tools'
export default {
  name: 'list',
  data () {
    return {
      inspectionArr: [],
      appoint_code: '',
      flag: '',
      appoint_start_time: '',
      appoint_end_time: '',
      start_time: '',
      end_time: '',
      errorTitle: '错误',
      formItem: {},
      dateArr: [], // 时间数组
      appointObj: {
        modal: false,
        title: '添加检测机构'
      },
      barcode_option: {
        displayValue: true, // 是否默认显示条形码数据
        // textPosition:'top', //条形码数据显示的位置
        background: '#fff', // 条形码背景颜色
        valid: function (valid) {
          console.log(valid, '11@@@@')
        },
        width: '1px', // 单个条形码的宽度
        height: '55px',
        fontSize: '22px' // 字体大小
      },
      barcodes: 'LM208861606907720718',
      personShow: false,
      sampleObj: {
        modal1: false, // 修正结果模态框
        sample_result: '',
        sample_code: ''
      },
      loadData: false,
      countData: {
        loading: false
      },
      searchInfo: {},
      params: {
        pageNo: 1,
        pageSize: 10,
        appoint_code: ''
      },
      params1: {
        pageNo: 1,
        pageSize: 10,
        sample_code: '',
        sample_status: '',
        sample_result: ''
      },
      currentPageNo: 1,
      currentPageSize: 10,
      totalnum: 0,
      currentPageNo1: 1,
      currentPageSize1: 10,
      totalnum1: 0,
      columns1: [
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '机构编号', key: 'jc_code', width: 200, align: 'center' },
        { title: '机构名称', key: 'jc_name', width: 164, align: 'center' },
        { title: '机构类型', key: 'jc_typeName', width: 150, align: 'center' },
        { title: '所属区', key: 'jc_type_codename', width: 150, align: 'center' },
        { title: '日检测能力', key: 'jc_max_num', width: 150, align: 'center' },
        { title: '创建时间', key: 'create_time', width: 120, align: 'center' },
        { title: '创建账号', key: 'create_by', width: 120, align: 'center' },
        { title: '操作', align: 'center', width: 120, slot: 'action' }
      ],
      fcDataList: [],
      columns2: [
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '姓名', key: 'name', width: 80, align: 'center' },
        { title: '证件号码', key: 'card_no', align: 'center' },
        { title: '联系电话', key: 'mobile', align: 'center' },
        { title: '详细地址', key: 'address', align: 'center' },
        { title: '预约状态', slot: 'state', align: 'center' },
        { title: '预约时间', key: 'appoint_create_time', align: 'center' }
      ],
      data2: [] // 预约人明细列表
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  watch: {
  },
  methods: {
    getQuList () {
      getQuList().then(res => {
        if (res.data.errcode === 0) {
          this.inspectionArr = res.data.data
        } else {
          this.$Notice.error({
            title: '查询区属列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    setAppoint (flag) { // 设置预约
      this.flag = flag
      this.formItem = {}
      this.appointObj.modal = true
    },
    okAppoint () {
      var url = ''
      if (this.flag === 'add') {
        url = createCompanyJC
      } else if (this.flag === 'edit') {
        url = updateCompanyJCByCode
      }
      url(this.formItem).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({
            title: '成功',
            desc: res.data.errmsg
          })
          this.appointObj.modal = false
          this.getList()
        } else {
          this.$Notice.error({
            title: '失败',
            desc: res.data.errmsg
          })
          this.getList()
          // console.log(this.fcDataList, 'leibiao ')
        }
      })
    },
    cancelAppoint () { // 关闭预约
      this.appointObj.modal = false
    },
    showdetail (item, flag) { // 编辑
      this.flag = flag
      this.appointObj.modal = true
      this.formItem = item
      this.appoint_start_time = this.formItem.appoint_start_time
      this.appoint_end_time = this.formItem.appoint_end_time
      this.start_time = this.formItem.start_time
      this.end_time = this.formItem.end_time
    },
    appointdetail (item) { // 预约详情
      this.personShow = true
      this.appoint_code = item.appoint_code
      this.getPersonList(item.appoint_code, 1)
    },
    deleteAppoint (item) {
      if (confirm('确定删除吗')) {
        deleteCompanyJCByCode({ jc_code: item.jc_code }).then(res => {
          if (res.data.errcode === 0) {
            this.$Notice.success({
              title: '删除成功',
              desc: res.data.errmsg
            })
            this.getList()
          } else {
            this.$Notice.error({
              title: '删除失败',
              desc: res.data.errmsg
            })
          }
        })
      }
    },
    pageAction (page) {
      this.params.pageNo = page
      this.getList()
    },
    selectlist () {
      this.params.pageNo = 1
      this.getList()
    },
    getList () {
      getCompanyJCList().then(res => {
        if (res.data.errcode === 0) {
          this.fcDataList = res.data.data.results
          let that = this
          this.fcDataList.forEach(function (temp) {
            if (that.inspectionArr.length > 0) {
              that.inspectionArr.forEach(function (tmp) {
                if (temp.jc_type_code === tmp.code) {
                  temp.jc_type_codename = tmp.name
                }
              })
            }
            if (temp.jc_type === '0') {
              temp.jc_typeName = '区属'
            }
            if (temp.jc_type === '1') {
              temp.jc_typeName = '市属'
            }
          })
          this.totalnum = res.data.data.totalRecord
        } else {
          this.$Notice.error({
            title: '查询列表信息失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    changePageNo (pageNo) {
      console.log(pageNo, '页数')
      this.currentPageNo = pageNo
      this.params.pageNo = pageNo
      this.getList(this.params)
    },
    changePageNo1 (pageNo) { // 预约人员列表
      console.log(pageNo, '页数')
      this.currentPageNo1 = pageNo
      this.params1.pageNo = pageNo
      this.getPersonList(this.appoint_code, pageNo)
    },
    getPersonList (appoint_code, pageNo) { // 获取送检人列表
      let param = {
        appoint_code: appoint_code,
        pageNo: pageNo,
        pageSize: 10
      }
      getAppointPersonList(param).then(res => {
        if (res.data.errcode === 0) {
          this.data2 = res.data.data.results
          this.totalnum1 = res.data.data.totalRecord
          console.log(this.data2, '明细列表')
        } else {
          this.$Notice.error({
            title: '获取预约人员列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    pageSizeChange (e) {
      this.params.pageSize = e
      this.selectlist(this.params.pageNo)
    },
    cancel () {
      this.personShow = false
    }
  },
  mounted () {
    var aa = document.getElementById('aaa')
    console.log(aa, 'aaaa')
    this.getList()
    this.getQuList()
    // JsBarcode('#barcode', '61606924060795', {
    //   format: 'CODE128',
    //   lineColor: '#000',
    //   background: '#EBEEF5',
    //   width: 0.5,
    //   height: 40,
    //   displayValue: false
    // })
  }
}
</script>

<style scoped>
    .page_style {
        margin: 20px 5px;
    }

    .input-frame {
        width: 120px;
        margin-right: 10px;
    }

    .house-list > .group {
        background: white;
        padding: 10px;
        margin-top: 10px;
    }

    .house-list > .group > .item {
        border-bottom: 1px solid #f5f5f5;
        padding: 10px 0;
    }

    .house-list > .group > .item .top {
        display: flex;
        justify-content: space-between;
        margin-bottom: 5px;
    }

    .house-list > .group > .item .title {
        font-size: 14px;
        color: #333333;
    }

    .house-list > .group > .item .address {
        font-size: 12px;
        color: gray;
        display: flex;
        align-items: center;
    }

    .house-list > .group > .item .detail {
        font-size: 12px;
        color: dodgerblue;
    }

    .opt-area-02 {
        display: flex;
        align-items: center;
        flex-direction: column;
        border: 1px solid #abdcff;
        background-color: #f0faff;
        padding: 8px 16px 8px 16px;
        border-radius: 4px;
        margin-bottom: 10px;
    }

    .opt-area-02 .right-con {
        width: 100%;
        margin-top: 5px;
        display: flex;
    }

    .opt-area-02 .left-con {
        font-size: 14px;
        width: 100%;
    }

    .opt-area-02 .left-con span {
        font-weight: bold;
    }

    .opt-area-02 .right-con input {
        width: 150px;
        margin-right: 10px;
    }

    .opt-area-02 .right-con .input-frame {
        width: 200px;
        margin-right: 10px;
    }

    .table-action-btn {
        margin-right: 3px;
    }

    .container >>> .ivu-btn-small {
        height: 24px;
        padding: 0 5px;
        font-size: 12px;
        border-radius: 3px;
    }

    .btn-action {
        margin-bottom: 10px;
    }

    .mp10 {
        margin-right: 10px;
    }
    .title-style {
      color: red;
    }
    .mb20 {
      margin-bottom: 20px;
    }
    .mt20 {
      margin-top: 20px;
    }
    .ivu-table-row {
      height: 57px;
    }
  .ivu-form-item-label {
    margin-top: 8px;
  }
    .demo-spin-icon-load{
      animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
      from { transform: rotate(0deg);}
      50%  { transform: rotate(180deg);}
      to   { transform: rotate(360deg);}
    }
    .demo-spin-col{
      height: 100px;
      position: relative;
      /*border: 1px solid #eee;*/
    }
</style>
